<%--
  Created by IntelliJ IDEA.
  User: luren
  Date: 2021/9/7
  Time: 8:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>欢迎登录</title>

    <link rel="stylesheet" href="style/style1.css" />
    <script src="js/jquery.min.js"></script>
    <script src="js/verificationNumbers.js" tppabs="js/verificationNumbers.js"></script>
    <script type="text/javascript">
        function login() {
            // 检查验证码是否输入或是否输入正确
            if (validate()) {
                let username = $(".username").val();
                let password = $(".password").val();
                // console.log(username + '   ' + password);
                $.ajax({
                    url: 'login.do',
                    data: {'username': username, 'password': password},
                    success: function (request) {
                        if (request === 'error') {
                            alert('账户名或密码错误');
                        }
                        if (request === 'ok') {
                            document.cookie = 'username = ' + username;
                            top.location = '/' + window.location.pathname.split('/')[1];
                        }
                    },
                    error: function (error) {
                        alert('登录失败')
                    }
                })
            }

        }
    </script>
</head>

<body>

<div class="login-container">
    <h1>用户登录</h1>

    <div class="connect">
        <p>欢迎来到空调售卖平台</p>
    </div>

    <form id="loginForm">
        <div>
            <input type="text" name="username" class="username" placeholder="用户名" autocomplete="off" />
        </div>

        <div>
            <input type="password" name="password" class="password" placeholder="密码" oncontextmenu="return false" onpaste="return false" />
        </div>

        <dd class="val_icon">
            <div class="checkcode">
                <input type="text" id="J_codetext" placeholder="验证码" maxlength="4" class="login_txtbx">
                <canvas class="J_codeimg" id="myCanvas" onclick="createCode()">对不起，您的浏览器不支持canvas，请下载最新版浏览器!</canvas>
            </div>
            <input type="button" value="验证码核验" class="ver_btn" onClick="validate();">
            <script>
                createCode();
            </script>
        </dd>

    </form>
    <button id="submit" onclick="login()">登 录</button>



    <a href="register.jsp">
        <button type="button" class="register-tis">还有没有账号？</button>
    </a>

</div>

<script src="js/common.js" type="text/javascript"></script>
<!--背景图片自动更换-->
<script src="js/supersized.3.2.7.min.js"></script>
<script src="js/supersized-init.js"></script>
<!--表单验证-->
<script src="js/jquery.validate.min.js?var1.14.0"></script>

</body>

</html>
